package com.edu.exam.enums;

/**
 * 图像处理任务类型枚举
 *
 * 从ProcessingTask类中提取的独立枚举类
 * 用于表示图像处理任务的不同类型
 *
 * @author System
 * @version 1.0.0
 */
public enum ImageProcessingTaskType {
    /**
     * 单张图像处理
     */
    SINGLE_IMAGE("SINGLE_IMAGE", "单张图像处理"),
    
    /**
     * 批量图像处理
     */
    BATCH_PROCESSING("BATCH_PROCESSING", "批量图像处理"),
    
    /**
     * 重新处理
     */
    REPROCESSING("REPROCESSING", "重新处理"),
    
    /**
     * 质量评估
     */
    QUALITY_ASSESSMENT("QUALITY_ASSESSMENT", "质量评估");

    private final String code;
    private final String description;

    ImageProcessingTaskType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 获取任务类型代码
     *
     * @return 任务类型代码
     */
    public String getCode() {
        return code;
    }

    /**
     * 获取任务类型描述
     *
     * @return 任务类型描述
     */
    public String getDescription() {
        return description;
    }

    /**
     * 从代码创建枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果代码无效
     */
    public static ImageProcessingTaskType fromCode(String code) {
        if (code == null) {
            throw new IllegalArgumentException("Code cannot be null");
        }
        for (ImageProcessingTaskType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    /**
     * 从描述创建枚举实例
     *
     * @param description 枚举描述
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果描述无效
     */
    public static ImageProcessingTaskType fromDescription(String description) {
        if (description == null) {
            throw new IllegalArgumentException("Description cannot be null");
        }
        for (ImageProcessingTaskType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}